package org.yonggan.dmp.tag

import org.apache.commons.lang3.StringUtils
import org.apache.spark.sql.Row
import org.yonggan.dmp.utils.UserTagUtils
import redis.clients.jedis.Jedis

/**
  * 广告类
  *     用户的标签
  *
  */
object AdTag extends  Tag {
  /**
    * 用户标签规范
    *
    * @param agrs 0 row
    *             1 jedis
    *
    * @return List[(String,Int)]  标签集合
    */
  override def makeTag(agrs: Any*): List[(String, Int)] = {

    var lst =  List[(String,Int)]()

    val row = agrs(0).asInstanceOf[Row]
    val jedis = agrs(1).asInstanceOf[Jedis]

    // 广告位类型
    val adtype:String = row.getAs[Int]("adspacetype").toString
    val adtypename = row.getAs[String]("adspacetypename")

    val adInfo:List[(String,Int)] = UserTagUtils.adSpaceType(adtype, adtypename)
    lst ++= adInfo


    // App 名称
    val appname = UserTagUtils.getAppName(row, jedis)
    lst ++= appname

    // 渠道Id
    val adplatformid  = row.getAs[Int]("adplatformproviderid").toString
    if (StringUtils.isNotEmpty(adplatformid)) lst :+= ("CN"+adplatformid,1)

    lst
  }
}
